package org.bing.zion.core;

import java.io.IOException;
import java.nio.ByteBuffer;

import org.bing.engine.common.logging.Log;
import org.bing.engine.common.logging.LogFactory;


public abstract class AbstractEventService {
	protected static final Log logger = LogFactory.getLog(AbstractEventService.class);

	/** session lifecycle */
	public void fireSessionCreated(Session session) {
		// logger.info("session created " + session);
	}

	public void fireSessionOpened(Session session) {
		logger.info("session opened " + session);
	}

	public void fireSessionClosed(Session session) {
		logger.info("session closed " + session);
	}

	/** message lifecycle */
	public void fireMessageReceived(Session session, Object message) {
		// logger.info("message received " + message);
		ProtocolFilterChain filterChain = session.getFilterChain();
		try {
			filterChain.first().messageReceived(filterChain, session, message);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public void fireMessageSent(Session session, Object message) {
		// logger.info("message sent " + message);
		ProtocolFilterChain filterChain = session.getFilterChain();
		try {
			filterChain.last().messageSent(filterChain, session, message);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public void fireMessageFlush(Session session, ByteBuffer buf) {
		// logger.info("message flush " + buf);
	}

	/** exception, impl by Filter, not use event */
	// public void fireExceptionCaught(Session session, Throwable t) {
	// logger.info("Exception caught " + session, t);
	// }

}
